<?php
/**
 * Created by PhpStorm.
 * User: liuhong
 * Date: 2019-04-09
 * Time: 16:54
 */

namespace app\service;


use app\common\model\VideoPay;
use app\common\model\VideoSubscribe;
use think\Db;
use think\Exception;

use GuzzleHttp\Client;

/**
 * 课程收藏列表
 * Class VideoSubscribeService
 * @package app\service
 */
class VideoSubscribeService extends BaseService
{
    public $videoSubscribeModel;

    public function __construct()
    {
        $this->videoSubscribeModel = new VideoSubscribe();
    }

    /**
     * 查询
     * @param $where
     * @param $page
     * @param int $page_num
     * @param string $filed
     * @return array|bool
     */
    public function queryPage($where, $page, $page_num = 20, $filed = '*')
    {
        try {
            $data = $this->videoSubscribeModel
                ->alias('a')
                ->join('zkhb_video b', 'a.video_id=b.id', 'left')
                ->order('a.id desc')
                ->field($filed)
                ->where($where)
                ->page($page, $page_num)
                ->select();
            if ($data) {
                $data = $data->toArray();
            }
            return $data;
        } catch (Exception $ex) {
            LogService::S()->writeLog('Exception', $ex->getMessage());
            return false;
        }
    }

    /**
     * 查询数量
     * @param $where
     * @return bool|int|string
     */
    public function queryCount($where)
    {
        try {
            return $this->videoSubscribeModel
                ->alias('a')
                ->join('zkhb_video b', 'a.video_id=b.id', 'left')
                ->order('a.id desc')
                ->where($where)
                ->count();
        } catch (Exception $ex) {
            LogService::S()->writeLog('Exception', $ex->getMessage());
            return false;
        }
    }
}